package cn.tedu.egweibo02.demos.web.controller;

import cn.tedu.egweibo02.demos.web.mapper.UserMapper;
import cn.tedu.egweibo02.demos.web.pojo.dto.UserDTO;
import cn.tedu.egweibo02.demos.web.pojo.entity.User;
import cn.tedu.egweibo02.demos.web.pojo.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Slf4j
@Api(tags = "用户模块")
@RestController
@RequestMapping("/v1/users/")
public class UserController {
    @Autowired
    private UserMapper userMapper;
    @PostMapping("reg")
    @ApiOperation(value = "用户注册功能")
    public int reg(@RequestBody UserDTO userDTO){
        log.debug("userDTO = " + userDTO);
        String username = userDTO.getUsername();
        UserLoginVO userLoginVO = userMapper.selectByUsername(username);
        log.debug("userLoginVO = " + userLoginVO);
        if (userDTO!=null){
            return 2;
        }
        User user = new User();
        BeanUtils.copyProperties(userDTO,user);
        user.setCreated(new Date());
        log.debug("user = " + user);
        userMapper.insert(user);
        return 1;
    }
    @PostMapping("login")
    @ApiOperation(value = "用户登录功能")
    public 
}
